// shopPages/Partner/Partner.js
import time_change from "../../utils/util.js";
var app = getApp()
var page = 1;
var newsList = [];
var selectedNews = false;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    memberSelectList: [
      {
        name: '今日',
        isSelect: true
      },
      {
        name: '昨日',
        isSelect: true
      },
      {
        name: '本周',
        isSelect: true
      },
      {
        name: '筛选',
        isSelect: true
      }
    ],
    staffselect:0,
    taskBack: false,
    start: '',
    end: '',
    list:[],
    totalCount:''
  },
  seleStaff: function (e) {
    var that = this
    page = 1
    newsList = []
    if (e.currentTarget.id  == 3){
      that.isShow()
      that.setData({ staffselect: e.currentTarget.id })
    } else if (e.currentTarget.id == 0){
      that.setData({ staffselect: e.currentTarget.id })
      that.getmyData('TODAY')
    }else if (e.currentTarget.id == 1) {
      that.setData({ staffselect: e.currentTarget.id })
      that.getmyData('YESTERDAY')
    }else if (e.currentTarget.id == 2) {
      that.setData({ staffselect: e.currentTarget.id })
      that.getmyData('WEEK')
    }
    
  },
  // 筛选显示
  isShow: function () {
    this.setData({ taskBack: true });
  },
  // 关闭筛选
  getData_hiden() {
    this.setData({
      taskBack: false
    })
  },
  // 筛选
  getData: function () {
    var that = this
    var taskBack = that.data.taskBack
    that.setData({
      taskBack: false
    })
    that.getmyData('SELECT_DAY', that.data.start, that.data.end)
  },

  bindDateChange: function (e) {
    this.setData({
      start: e.detail.value
    })
  },
  bindDateChange1: function (e) {
    this.setData({
      end: e.detail.value
    })
  },
  getmyData(dateType, startDay, endDay) {
    var that = this
    wx.request({
      url: app.globalData.bossradar + '/api/1.0/partnerLogList',
      data: {
        uid: app.globalData.userInfo.id,
        dateType: dateType,
        startDay: startDay,
        endDay: endDay
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      method: 'POST',
      success: function (res) {
        console.log(res)
        for (var i = 0; i < res.data.data.list.length; i++) {
          var time = time_change.imestampToTime(res.data.data.list[i].createTime)
          res.data.data.list[i].show_time = time;
          newsList.push(res.data.data.list[i]);
        }
        if (res.data.data.list.length < 20) {
          selectedNews = false;
        } else {
          selectedNews = true;
          page += 1;
        }
        that.setData({
          list: newsList,
          totalCount: res.data.data.totalCount
        });
        wx.hideLoading();
      },
      fail: function (res) {
        console.log(">>>>>>>>>>>失败")
      },
      complete: function (res) { },
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var day3 = new Date();
    day3.setTime(day3.getTime());
    var month = day3.getMonth() + 1;
    if (month.toString().length == 1) {
      month = '0' + month;
    }
    var day = day3.getDate();
    if (day.toString().length == 1) {
      day = '0' + day;
    }
    var start = day3.getFullYear() + "-" + month + "-01";
    var end = day3.getFullYear() + "-" + month + "-" + day;
    that.setData({
      start: start,
      end: end
    });
    page = 1
    selectedNews = false;
    newsList = []
    that.getmyData('TODAY')
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (selectedNews == true) {
      var that = this;
      // 显示加载图标  
      wx.showLoading({
        title: '玩命加载中',
      })
      // 页数+1  
      if (that.data.staffselect == 3) {
        that.getmyData('SELECT_DAY', that.data.start, that.data.end)
      } else if (that.data.staffselect == 0) {

        that.getmyData('TODAY')
      } else if (that.data.staffselect == 1) {

        that.getmyData('YESTERDAY')
      } else if (that.data.staffselect == 2) {

        that.getmyData('WEEK')
      }

    } else {
      wx.hideLoading();
    }
  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // }
})